package com.xmut.eduservice.controller;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xmut.commonutils.R;
import com.xmut.eduservice.entity.EduComment;
import com.xmut.eduservice.entity.EduCourseCollect;
import com.xmut.eduservice.entity.EduVideo;
import com.xmut.eduservice.service.EduCommentService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 评论 前端控制器
 * </p>
 *
 * @author huangchaoqin
 * @since 2020-08-04
 */
@RestController
@CrossOrigin
@RequestMapping("/eduservice/edu-comment")
public class EduCommentController {
    @Autowired
    EduCommentService eduCommentService;
    // 根据课程id查询评论
    @ApiOperation(value = "根据课程id查询所有评论")
    @GetMapping("getAllCommentByCourseId/{courseId}")
    public R getAllCommentByCourseId(@PathVariable String courseId) {
        QueryWrapper<EduComment> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("course_id", courseId);
        List<EduComment> list = eduCommentService.list(queryWrapper);
        return R.ok().data("list", list);
    }

    @ApiOperation(value = "新增评论")
    @PostMapping("addComment")
    public R addComment(@RequestBody EduComment eduComment){
        eduCommentService.save(eduComment);
        return R.ok();
    }
}

